package dryven.model.binding.form;

import dryven.model.binding.fieldset.FieldSet;
import dryven.model.binding.proxy.Binding;
import dryven.model.validation.ErrorMessageCollection;
import dryven.model.validation.ValidatorSession;

public class FormValidation {
	private DecodedFormModelCollection _models;
	private ValidatorSession _validatorSession;
	private Binding<FieldSet> _fieldSetBinding;
	
	public FormValidation(DecodedFormModelCollection models,
			ValidatorSession validatorSession, Binding<FieldSet> fieldSetBinding) {
		super();
		_models = models;
		_validatorSession = validatorSession;
		_fieldSetBinding = fieldSetBinding;
	}
	
	public boolean belongsToForm(Form f) {
		return f.getAction().getAction().equals(_fieldSetBinding.getBoundMethod());
	}

	public <T> T getValidatedModel(Class<T> clazz) {
		return _models.getModel(clazz);
	}

	public ErrorMessageCollection getErrorMessages() {
		return _validatorSession.getErrorMessages();
	}

	public boolean hasErrors() {
		return _validatorSession.hasErrors();
	}
}
